$(function() {

	initpatientTest();


	/*获心理自测首页*/
	function initpatientTest(){
		var param = {"pageNo":1,"type":11,"pageSize":999};
		function callBackSlider(data){
			console.log(data);
			var html1 = "";
			/*渲染导航栏*/
			for (i in data.evaluatingCategoriesList) {
				html1 += '<div class="font3 clickList" data-id="'+data.evaluatingCategoriesList[i].id+'"><span><i class="iconfont icon-00'+(parseInt(i)+5)+'"></i><p>'+data.evaluatingCategoriesList[i].typeName+'</p></span></div>';
			}
			$(".patient-test-nav").prepend(html1);
			/*渲染题目列表*/
			getTestList(data.evaluatingList);
			
		}
		patientTestmodule.patientTest(param,callBackSlider);
	}
	/*渲染题目列表*/
	function getTestList(data){
		if(typeof(data.evaluatingList)  !="undefined"){
			data=data.evaluatingList;
		}
		var html = "";
		for (i in data) {
				var datetime =data[i].createTime;
				var date=datetime.substring(0,10);
				var dates=date.split("-");
				var $datetime = dates[1]+'月'+dates[2]+'日';
				html += '<li class="mui-table-view-cell mui-media"><a href="javascript:;" class="intoinfo" data-href="./patient-test1.html?id='+data[i].id+'"><img class="mui-media-object mui-pull-left" src="'+data[i].picurl+'"><div class="mui-media-body"><div class="mui-ellipsis font4">'+data[i].title+'</div><p class="font1"><font>'+data[i].participantcount+'</font>人测试过</p><p class="create-time font1">'+$datetime+'</p></div></a></li>';
		}
		$(".notest").hide();
		$(".mui-table-view").empty();
		if(data.length>0){
			
			$(".mui-table-view").prepend(html);
		}else{
			$(".notest").show();
		}
		
	}
	$($(".patient-test-nav div")[0]).find("span").addClass("active");
	$(".patient-test-nav div span").click(function(){
		$(this).addClass("active");
		$(this).parent().siblings().find("span").removeClass("active");
	});
	
	$(".html-loding").hide();
	
	/*绑定筛选类型*/
	$(".clickList").bind("click",function(){
		var id = $(this).data("id");
		var param = {"pageNo":1,"type":id,"pageSize":999};
		patientTestmodule.patientTest(param,getTestList);
		
	});
	/*绑定 点击 进入详情*/
	$(".intoinfo").live("click",function(){
		var herf = $(this).data("href");
		mui.openWindow({
			url:herf,
		});
		
	});
	/*绑定 点击 进入答题*/
	$(".cilckTest").live("click",function(){
		var herf = $(this).data("href");
		mui.openWindow({
			url:herf,
		});
		
	});
	/*绑定 点击 进入我的*/
	$(".clickMy").live("click",function(){
		var param = {"patientid":USERID};
		patientTestmodule.getEvaluatingUserList(param,callBack);
		function callBack(data){
			console.log(data);
			/*渲染题目列表*/
			if($.isEmptyObject(data.result) && typeof(data.length)  =="undefined"){
				$(".mui-table-view").empty();
				$(".notest").show();
			}else{
				getTestList(data);
			}
			
			
		}
		
		
	});
	var widHeight=document.documentElement.clientHeight;
	var testHeight=$("header").height();
	$(".notest").height(widHeight-testHeight);
}); 